<%@ page  pageEncoding="utf-8"%>
<%@page import="org.myhibernate.Template"%>
<%@page import="org.myhibernate.ProxyTemplate"%>
<%@page import="org.myhibernate.core.method.PageSizeQuery"%>
<%@page import="java.util.List"%>
<%@page import="org.json.JSONArray"%>
<%@page import="org.json.JSONObject"%>
<%@page import="java.util.ArrayList"%>
<%@page import="org.personal.entity.Portlet"%>
<%@page import="org.personal.entity.User"%>
<%@page import="org.personal.Constants"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
int start=0,size=15,count=0;
if(request.getParameter("start")!=null){start=Integer.parseInt(request.getParameter("start"));}
if(request.getParameter("size")!=null){size=Integer.parseInt(request.getParameter("size"));}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>选择板块</title> 
<%@include file="../styles/styles.jsp" %>

  </head>
  <body>
  
     <div id="listtable" >
  <table cellspacing="0" cellpadding="0" class="tab"  style="width:100%;display:;"  >
  <thead>
	<tr><td>名称</td><td>操作</td></tr></thead>
<%
   	Template template=new ProxyTemplate(Portlet.class).getInstance();
	PageSizeQuery query=template.getPageSizeQuery();
	List list=null;
	Portlet portlet=null;
	User user=(User)request.getSession().getAttribute(Constants.USER);
	if(user != null)
	{
		List groups=user.getGroups();
		StringBuffer sql=new StringBuffer();
		sql.append(" where (editUsers like '%;"+user.getUid()+";%' ) or (editUsers like '%;"+Constants.USER_ALLUSER+";%' ) ");
		//System.out.println("groups="+groups);
		for(int i=0;i<groups.size();i++)
		{
			sql.append(" or (editUsers like '%;"+groups.get(i)+";%' ) ");
		}
		count=query.query(sql.toString());
		list=query.getListObject(start,start+size);
	}else
	{
		list=new ArrayList();
	}
	

   	try
   	{
   		for(int i=0;i<list.size();i++)
   		{
   			portlet=(Portlet)list.get(i);
   			%>
				<tr>
    				<td><%=portlet.getTitle()%></td>
					<td>
    				<a href="javascript:;" onclick="actionFunction('choose','<%=portlet.getId()%>')" >选择</a>&nbsp;&nbsp;
    				</td>
    				</tr>   			
   			<%
   		}
   	}catch(Exception exception){}
   	finally
   	{
   		template.close();
   	}	
   	if(count == 0)
    {
    	out.println("<tr><td colspan=2 align=center >暂无数据</td></tr>");
    }	
%>
</table>
<div id="pagenav"></div>
   </div>

<script>
var map=new Object();
var start=<%=start%>;
var size=<%=size%>;
var count=<%=count%>;
var currentPage=(start/size)+1;
function get(id){return document.getElementById(id);}
var message=get("message");
function pageNavCall(index)
{
	//alert(index);
	var tempStart=(index-1)*size;
	var args="start="+tempStart+"&size="+size;
	args=encodeURI(encodeURI(args));
	window.location.href="<%=basePath%>admin/portlet.jsp?"+args;
}
var pageNav=new PageNavgation();
pageNav.setHandle(pageNav);
pageNav.setCall(pageNavCall);
pageNav.setAllCount(count);
pageNav.setPageSize(size);
pageNav.setCurrentPage(currentPage);
pageNav.bind("pagenav");
var currentId="";

function actionFunction(type,id,title)
{
	if("choose" == type)
	{
		try
		{
			window.parent.addPortlet(id);
		}catch(e)
		{
			alert(e);
		}
	}
}

</script>
  </body>
</html>
